package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Exchangegift;
import cn.wolfcode.crm.query.ExchangegiftQueryObject;
import cn.wolfcode.crm.service.IExchangegiftService;
import cn.wolfcode.crm.service.IMemberService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("exchangegift")
public class ExchangegiftController {

    @Autowired
    private IExchangegiftService exchangegiftService;

    @Autowired
    private IMemberService mamberService;

    @RequestMapping("")
    public String index(){
        return "exchangegift/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ExchangegiftQueryObject qo){
        PageResult result = exchangegiftService.query(qo);
        int a = 1;
        return exchangegiftService.query(qo);

    }
    @RequestMapping("update")
    @ResponseBody
    public JsonResult save(Exchangegift entity){

        try{
            exchangegiftService.update(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("保存失败");
        }

        return new JsonResult();

    }
    @RequestMapping("save")
    @ResponseBody
    public JsonResult update(Exchangegift entity){

        try{
            entity.setInputuserUsername("李超凡");
            entity.setExchangedate(new Date());
            exchangegiftService.save(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("兑换失败");
        }
        System.out.println(entity);

        return new JsonResult();

    }
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if(id != null){
        try{
            exchangegiftService.delete(id);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("删除失败");
        }
        }

        return new JsonResult();

    }

    @RequestMapping("pointsChange")
    public String change(){
        return "exchangegift/pointsChange";
    }


}
